import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-03-11
 * Time:22:34
 */
@WebServlet("/postParameter")
public class PostParameterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        //约定：前端构造形如这样的请求：
        //POST/pastm=Parameter
        //Content-Type:application/x-www-form-urlencode
        //username=zhangsan&password=123
        //就需要在后端代码中把body中的值给拿到。
        //获取值的方法仍然是getParameter
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        System.out.println("username"+username);
        System.out.println("password"+password);
        resp.getWriter().write("ok");
    }
}
